/**
 * 分页
 * <pre>
 * 作者：lvmiancan
 * 邮箱：550804606@qq.com
 * 日期：2018-04-10 15:07:33
 * 版权：苏州东大金点物联科技有限公司
 * </pre>
 */
$(function(){
	pagesControl = new PagesControl();
	pagesControl.init();  //初始化操作
});
(function() {
	

	PagesControl = function() {
		//定义属性
	};

	/**
	 * 方法
	 */
	PagesControl.prototype = {
			/**
			 * 初始化
			 */
			init : function() {
				if (this.hasInit) // 是否已初始化
					return false;
				this.hasInit = true;
	
				this.initPagesData();
			},
			initPagesData:function(){
				initHtml = '<div class="fr-pagination page-chain-number"><ul class=" pages">';
				$(".step-page").each(function(i){
					$el = $(this)
					_title = $el.data("title")
					index =i+1; 
					_id= "step"+index;
					$el.attr("id", _id );
					_nexts = $el.nextAll();
					_nexts.each(function(i){
						_el = $(this)
						boot = _el.hasClass("step-page");
						if(boot){
							return false;
						}else{
							$el.append(_el);
						}
					})
					if(i == 0){
						_next = $el.data("next")
						_prev = $el.data("prev")
						initBut = '<div class="nav navbar-toolbar  navbar-right"><a class="btn  btn-primary   fa fa-chevron-circle-left "href="javascript:void(0)"><span>'
							          +_prev+'</span></a> <a class="btn  btn-primary   fa fa-chevron-circle-right"href="javascript:void(0)"><span>'
							          +_next+'</span></a></div>'
						$(".panel-toolbar").append(initBut);
						$el.show();
						initLi='<li class="active" data-step="'+index+'"><div class="page-number">'+index+'</div><div class="page-desc">'
						+'<span class="page-title"> '+_title+'</span><p class="page-help-block"></p></div></li>';
					}else{
						$el.hide()
						initLi='<li  data-step="'+index+'"><div class="page-number">'+index+'</div><div class="page-desc">'
						+'<span class="page-title"> '+_title+'</span><p class="page-help-block"></p></div></li>';
						
					}
					initHtml +=initLi;
				})
				initHtml += '</ul></div>'
				total = $(".step-page").length;//分页总数
				if(total>0){
					$("form").prepend(initHtml);
					num = 1;//第一页
					$(".fa-chevron-circle-right").on("click", function(){
						if(num<total){
							$("#step"+num).hide();
							num++;
							$("#step"+num).show();
							$("li[data-step="+num+"]").addClass("active");
						}
					});
					$(".fa-chevron-circle-left").on("click", function(){
						if(num<=total  &&  num >1){
							$("#step"+num).hide();
							$("li[data-step="+num+"]").removeClass("active");
							num--;
							$("#step"+num).show();
						}
					});
				}
			},
	}
})();